package scitc.alumni.util;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.stereotype.Component;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Component
public class ResponseUtil {
    private Integer code;
    private String msg;
    private Object data;

    // 成功的情形
    public ResponseUtil success() {
        return new ResponseUtil(0, "成功", null);
    }
    // 使用最多
    public ResponseUtil success(Object data) {
        return new ResponseUtil(0, "成功", data);
    }
    public ResponseUtil success(String msg, Object data) {
        return new ResponseUtil(0, msg, data);
    }
    // 失败的情形
    public ResponseUtil fail() {
        return new ResponseUtil(500, "失败", null);
    }
    public ResponseUtil fail(String msg) {
        return new ResponseUtil(500, msg, null);
    }
    public ResponseUtil fail(Integer code, String msg) {
        //return new ResponseUtil(code, msg, null);
        return ResponseUtil.builder().code(code).msg(msg).build();

    }
}
